<?php
//header("Content-Type:text/html; charset=utf-8");
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
function replacebd($str1,$str2){
 $s1=explode("Brand Name:",$str1);
 $s2=explode('&lt;br/&gt;',$s1[1]);
 $s3=str_replace($s2[0],$str2,$str1);
 return $s3;
}
function randomkeys($length)   
{   
   //$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ'; 
      $str = null;
      $strPol = "123456789";//大小写字母以及数字
      $max = strlen($strPol)-1;
      
      for($i=0;$i<$length;$i++){
         $str.=$strPol[rand(0,$max)];
      }
      return $str;
}
function EAN13($n){
        $n=(string)$n;
        $a=(($n[1]+$n[3]+$n[5]+$n[7]+$n[9]+$n[11])*3+$n[0]+$n[2]+$n[4]+$n[6]+$n[8]+$n[10])%10;
        $a=$a==0?0:10-$a;
        return $n.$a;
    }
$lang=$_GET["lang"];
$bname=$_GET["bname"];
$brand=$_POST["brand"];
$ProductType=$_POST["ProductType"];
$manufacturer=$_POST["manufacturer"];
$recommended=$_POST["recommended"];
$user_name=$_SESSION["managername"];
if($_SESSION["thetype"]=="超级管理员"){$sql="select * from ph_".$lang." where 1=1";}
if($_SESSION["thetype"]=="管理员"){
$query="select admin from ph_admin where admin='".$_SESSION["managername"]."' or parent='".$_SESSION["managername"]."'";
$resulty=mysqli_query($conn,$query);
$array=array();
while($rowy = mysqli_fetch_array($resulty)){
array_push($array,"'".$rowy[admin]."'");
}
$alluser=implode(',', $array);
$sql="select * from ph_".$lang." where 1=1 and user_name in(".$alluser.")";}
if($_SESSION["thetype"]=="员工"){$sql="select * from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";}
if($bname!==''&&isset($bname)){$sql.=" and bname ='".$bname."'";}
$result=mysqli_query($conn,$sql);
#使用轻量级的excel操作库PHP_XLSXWriter
$timeStart = microtime(true);
require_once("../PHP_XLSXWriter/vendor/autoload.php");
//require_once("xlsxwriter.class.php");
$writer = new XLSXWriter();
$filename = $bname."-".date('Ymdhis', time()).".xlsx";
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$sheetHeader1 = [
    'TemplateType=fptcustom',
    'Version=2018.0727',
    'TemplateSignature=S0lUQ0hFTg==',
    'The top 3 rows are for Amazon.com use only. Do not',
    '',
	'',
	'',
	'',
	'',
	'',
	'Images',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'Variation',
	'',
	'',
	'',
	'Basic',
	'',
	'',
	'',
	'',
	'',
	'Discovery',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'Product Enrichment',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'Dimensions',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'Fulfillment',
	'',
	'',
	'',
	'',
	'',
	'',
	'Compliance',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'Offer',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'b2b',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	''
];
$sheetHeader2 = [
    'Product Type',
    'Seller SKU',
    'Brand Name',
    'Product Name',
    'Manufacturer',
	'Recommended Browse Nodes',
	'Standard Price',
	'Quantity',
	'Merchant Shipping Group',
	'Main Image URL',
	'Swatch Image URL',
	'Other Image Url',
	'Other Image Url',
	'Other Image Url',
	'Other Image Url',
	'Other Image Url',
	'Other Image Url',
	'Other Image Url',
	'Other Image Url',
	'Parentage',
	'Parent SKU',
	'Relationship Type',
	'Variation Theme',
	'Update Delete',
	'GTIN Exemption Reason',
	'Product ID',
	'Product ID Type',
	'Manufacturer Part Number',
	'Product Description',
	'Merchant Catalogue Number',
	'Key Product Features',
	'Key Product Features',
	'Key Product Features',
	'Key Product Features',
	'Key Product Features',
	'Key Product Features',
	'Search Terms',
	'Search Terms',
	'Search Terms',
	'Search Terms',
	'Search Terms',
	'Platinum Keyword',
	'Platinum Keyword',
	'Platinum Keyword',
	'Platinum Keyword',
	'Platinum Keyword',
	'Home & Furniture Target Audience',
	'size_map',
	'length_range',
	'width_range',
	'Scent',
	'Colour',
	'Color Map',
	'Size',
	'Material Type',
	'Item Width Unit Of Measure',
	'item_width',
	'item_height',
	'Item Height Unit Of Measure',
	'Item Dimensions Unit Of Measure',
	'Item Length Unit Of Measure',
	'item_length',
	'Display Depth',
	'Item Display Depth Unit Of Measure',
	'Shipping Weight',
	'Website Shipping Weight Unit Of Measure',
	'Vacuum Sealer Bag Length',
	'Item Display Length Unit Of Measure',
	'Display Width',
	'Item Display Width Unit Of Measure',
	'Display Height',
	'Item Display Height Unit Of Measure',
	'Display Diameter',
	'Item Display Diameter Unit Of Measure',
	'Vacuum & Floor Care Item Weight',
	'Item Display Weight Unit Of Measure',
	'Volume',
	'Volume Capacity Name Unit Of Measure',
	'Volume Capacity of the appliance',
	'Item Display Volume Unit Of Measure',
	'Package Weight Unit Of Measure',
	'Package Dimensions Unit Of Measure',
	'package_weight',
	'Package Length',
	'Package Width',
	'Package Height',
	'Fulfillment Centre ID',
	'specific_uses_for_product1',
	'specific_uses_for_product2',
	'specific_uses_for_product3',
	'specific_uses_for_product4',
	'specific_uses_for_product5',
	'Product fiche',
	'Energy efficiency label',
	'legal_disclaimer_description',
	'safety_warning',
	'fedas_id',
	'EU Toys Safety Directive Age-Specific Warning',
	'EU Toys Safety Directive Non-Age-Specific Warning',
	'EU Toys Safety Directive Language Warning',
	'Country/Region of declaration',
	'Batteries are Included',
	'Is this product a battery or does it utilise batte',
	'Battery type/size',
	'Battery type/size',
	'Battery type/size',
	'Number of batteries',
	'Number of batteries',
	'Number of batteries',
	'Battery composition',
	'Battery weight (grams)',
	'battery_weight_unit_of_measure',
	'Number of Lithium Metal Cells',
	'Number of Lithium-ion Cells',
	'Lithium Battery Packaging',
	'Watt hours per battery',
	'lithium_battery_energy_content_unit_of_measure',
	'Lithium content (grams)',
	'lithium_battery_weight_unit_of_measure',
	'Applicable Dangerous Goods Regulations',
	'Applicable Dangerous Goods Regulations',
	'Applicable Dangerous Goods Regulations',
	'Applicable Dangerous Goods Regulations',
	'Applicable Dangerous Goods Regulations',
	'UN number',
	'Safety Data Sheet (SDS) URL',
	'Item Weight',
	'item_weight_unit_of_measure',
	'Volume',
	'item_volume_unit_of_measure',
	'Flash point (°C)?',
	'Categorization/GHS pictograms (select all that app',
	'Categorization/GHS pictograms (select all that app',
	'Categorization/GHS pictograms (select all that app',
	'Recommended Retail Price',
	'weee_tax_value',
	'Number of Items',
	'weee_tax_value_unit_of_measure',
	'Stop Selling Date',
	'Max Order Quantity',
	'Offering Release Date',
	'Scheduled Delivery SKU List',
	'Launch Date',
	'Currency',
	'Package Quantity',
	'Product Tax Code',
	'Release Date',
	'Sale Price',
	'Sale From Date',
	'Sale End Date',
	'Item Condition',
	'Offer Condition Note',
	'Handling Time',
	'Restock Date',
	'Maximum Aggregate Ship Quantity',
	'Can Be Gift Messaged',
	'Is Gift Wrap Available?',
	'Is Discontinued by Manufacturer',
	'Registered Parameter',
	'Business Price',
	'Quantity Price Type',
	'Quantity Lower Bound 1',
	'Quantity Price 1',
	'Quantity Lower Bound 2',
	'Quantity Price 2',
	'Quantity Lower Bound 3',
	'Quantity Price 3',
	'Quantity Lower Bound 4',
	'Quantity Price 4',
	'Quantity Lower Bound 5',
	'Quantity Price 5',
	'National Stock Number',
	'United Nations Standard Products and Services Code',
	'Pricing Action'
];
$sheetHeader3 = [
    'feed_product_type',
    'item_sku',
    'brand_name',
    'item_name',
    'manufacturer',
	'recommended_browse_nodes',
	'standard_price',
	'quantity',
	'merchant_shipping_group_name',
	'main_image_url',
	'swatch_image_url',
	'other_image_url1',
	'other_image_url2',
	'other_image_url3',
	'other_image_url4',
	'other_image_url5',
	'other_image_url6',
	'other_image_url7',
	'other_image_url8',
	'parent_child',
	'parent_sku',
	'relationship_type',
	'variation_theme',
	'update_delete',
	'gtin_exemption_reason',
	'external_product_id',
	'external_product_id_type',
	'part_number',
	'product_description',
	'catalog_number',
	'bullet_point1',
	'bullet_point2',
	'bullet_point3',
	'bullet_point4',
	'bullet_point5',
	'bullet_point6',
	'generic_keywords1',
	'generic_keywords2',
	'generic_keywords3',
	'generic_keywords4',
	'generic_keywords5',
	'platinum_keywords1',
	'platinum_keywords2',
	'platinum_keywords3',
	'platinum_keywords4',
	'platinum_keywords5',
	'target_audience_keywords',
	'size_map',
	'length_range',
	'width_range',
	'scent_name',
	'color_name',
	'color_map',
	'size_name',
	'material_type',
	'item_width_unit_of_measure',
	'item_width',
	'item_height',
	'item_height_unit_of_measure',
	'item_dimensions_unit_of_measure',
	'item_length_unit_of_measure',
	'item_length',
	'item_display_depth',
	'item_display_depth_unit_of_measure',
	'website_shipping_weight',
	'website_shipping_weight_unit_of_measure',
	'item_display_length',
	'item_display_length_unit_of_measure',
	'item_display_width',
	'item_display_width_unit_of_measure',
	'item_display_height',
	'item_display_height_unit_of_measure',
	'item_display_diameter',
	'item_display_diameter_unit_of_measure',
	'item_display_weight',
	'item_display_weight_unit_of_measure',
	'volume_capacity_name',
	'volume_capacity_name_unit_of_measure',
	'item_display_volume',
	'item_display_volume_unit_of_measure',
	'package_weight_unit_of_measure',
	'package_dimensions_unit_of_measure',
	'package_weight',
	'package_length',
	'package_width',
	'package_height',
	'fulfillment_center_id',
	'specific_uses_for_product1',
	'specific_uses_for_product2',
	'specific_uses_for_product3',
	'specific_uses_for_product4',
	'specific_uses_for_product5',
	'product_efficiency_image_url',
	'energy_efficiency_image_url',
	'legal_disclaimer_description',
	'safety_warning',
	'fedas_id',
	'eu_toys_safety_directive_age_warning',
	'eu_toys_safety_directive_warning',
	'eu_toys_safety_directive_language',
	'country_string',
	'are_batteries_included',
	'batteries_required',
	'battery_type1',
	'battery_type2',
	'battery_type3',
	'number_of_batteries1',
	'number_of_batteries2',
	'number_of_batteries3',
	'battery_cell_composition',
	'battery_weight',
	'battery_weight_unit_of_measure',
	'number_of_lithium_metal_cells',
	'number_of_lithium_ion_cells',
	'lithium_battery_packaging',
	'lithium_battery_energy_content',
	'lithium_battery_energy_content_unit_of_measure',
	'lithium_battery_weight',
	'lithium_battery_weight_unit_of_measure',
	'supplier_declared_dg_hz_regulation1',
	'supplier_declared_dg_hz_regulation2',
	'supplier_declared_dg_hz_regulation3',
	'supplier_declared_dg_hz_regulation4',
	'supplier_declared_dg_hz_regulation5',
	'united_nations_regulatory_id',
	'safety_data_sheet_url',
	'item_weight',
	'item_weight_unit_of_measure',
	'item_volume',
	'item_volume_unit_of_measure',
	'flash_point',
	'ghs_classification_class1',
	'ghs_classification_class2',
	'ghs_classification_class3',
	'list_price',
	'weee_tax_value',
	'number_of_items',
	'weee_tax_value_unit_of_measure',
	'offering_end_date',
	'max_order_quantity',
	'offering_start_date',
	'delivery_schedule_group_id',
	'product_site_launch_date',
	'currency',
	'item_package_quantity',
	'product_tax_code',
	'merchant_release_date',
	'sale_price',
	'sale_from_date',
	'sale_end_date',
	'condition_type',
	'condition_note',
	'fulfillment_latency',
	'restock_date',
	'max_aggregate_ship_quantity',
	'offering_can_be_gift_messaged',
	'offering_can_be_giftwrapped',
	'is_discontinued_by_manufacturer',
	'missing_keyset_reason',
	'business_price',
	'quantity_price_type',
	'quantity_lower_bound1',
	'quantity_price1',
	'quantity_lower_bound2',
	'quantity_price2',
	'quantity_lower_bound3',
	'quantity_price3',
	'quantity_lower_bound4',
	'quantity_price4',
	'quantity_lower_bound5',
	'quantity_price5',
	'national_stock_number',
	'unspsc_code',
	'pricing_action'
];
//$writer->writeSheetHeader('Sheet1',  $sheetHeader1);//optional
$writer->writeSheetRow('Sheet1', $sheetHeader1);
$writer->writeSheetRow('Sheet1', $sheetHeader2);
$writer->writeSheetRow('Sheet1', $sheetHeader3);
while($row=mysqli_fetch_array($result)){
    $key1="";
	$key2="";
	$key3="";
	$key4="";
	$key5="";
	$img1="";
	$img2="";
	$img3="";
	$img4="";
	$img5="";
	$img6="";
	$img7="";
	$img8="";
	$img9="";
	if(!empty($row["keywords"])){
	$key=explode("\r\n",$row["keywords"]);
	if(!empty($key[0])){$key1=$key[0];}
	if(!empty($key[1])){$key2=$key[1];}
	if(!empty($key[2])){$key3=$key[2];}
	if(!empty($key[3])){$key4=$key[3];}
	if(!empty($key[4])){$key5=$key[4];}
	}
	
	$sqla="select * from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$row["ID"]."' and btid is null order by px,id asc) t order by px,id asc)";
	$resulta=mysqli_query($conn,$sqla);
	while($rowa=mysqli_fetch_array($resulta)){
	if(!empty($rowa["imgpath"])){$img1="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img1="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img2="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img2="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img3="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img3="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img4="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img4="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img5="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img5="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img6="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img6="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img7="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img7="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img8="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img8="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img9="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img9="";}
	}
	$rowa=null;
	unset($rowa);
    $spliter="<br/>";
	$content=str_replace("\r\n",$spliter,$row["content"]);
    $content=htmlentities($content);
  $sqls="select * from ph_shuxing where proid='".$row["ID"]."' order by ID asc";
  $results=mysqli_query($conn,$sqls);
  $sku=$row["skucode"];
  $content=replacebd($content,$brand);
  if(strpos($row["sketch"], $spliter)==false){
    $des=explode($spliter,$content);
  }else{
    $des=explode("<br/>",$row["sketch"]);
  }
	$des1=$des[0];
	$des2=$des[1];
	$des3=$des[2];
	$des4=$des[3];
	$des5=$des[4];
	$des6=$des[5];
$tbody=[
    $ProductType,
    $sku,
    $brand,
    $row["proname"],
    $manufacturer,
	$recommended,
	$row["saleprice"],
	$row["kucun"],
	'Migrated Template',
	$img1,
	$img1,
	$img2,
	$img3,
	$img4,
	$img5,
	$img6,
	$img7,
	$img8,
	$img9,
	'parent',
	'',
	'',
	$row["btname"],
	'',
	'',
	'',
	'',
	'',
	$content,
	'',
	$des1,
	$des2,
	$des3,
	$des4,
	$des5,
	$des6,
	$key1,
	$key2,
	$key3,
	$key4,
	$key5,
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'New',
	'',
	'10',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	''
];
$writer->writeSheetRow('Sheet1', $tbody);
if(mysqli_num_rows($results)<1){
	$tbody=[
    $ProductType,
    $sku."-1",
    $brand,
    $row["proname"],
    $manufacturer,
	$recommended,
	$row["saleprice"],
	$row["kucun"],
	'Migrated Template',
	$img1,
	$img1,
	$img2,
	$img3,
	$img4,
	$img5,
	$img6,
	$img7,
	$img8,
	$img9,
	'child',
	$sku,
	'Variation',
	$row["btname"],
	'update',
	'',
	EAN13(randomkeys(12)),
	'EAN',
	'',
	$content,
	'',
	$des1,
	$des2,
	$des3,
	$des4,
	$des5,
	$des6,
	$key1,
	$key2,
	$key3,
	$key4,
	$key5,
	'',
	'',
	'',
	'',
	'',
	'',
	'One size',
	'',
	'',
	'',
	'color',
	'color',
	'One size',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'New',
	'',
	'10',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	''
];
$writer->writeSheetRow('Sheet1', $tbody);
}else{
  $i=0;
  while($rows=mysqli_fetch_array($results)){
  $btimg1="";
  $btimg2="";
  $btimg3="";
  $btimg4="";
  $btimg5="";
  $btimg6="";
  $btimg7="";
  $btimg8="";
  $btimg9="";
  $i=$i+1;
  if(strpos($rows["cname"],",")!==false){$cname=explode(",",$rows["cname"]);$cname1=$cname[0];$cname2=$cname[1];}else{$cname1=$rows["cname"];$cname2="";}
    $sqlb="select * from ph_img where id in(select imgid from(select imgid from ph_proimg where btid='".$rows["ID"]."' order by id asc) t order by id asc)";
	$resultb=mysqli_query($conn,$sqlb);
	while($rowb=mysqli_fetch_array($resultb)){

	if(!empty($rowb["imgpath"])){$btimg1="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg1=$img1;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg2="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg2=$img2;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg3="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg3=$img3;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg4="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg4=$img4;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg5="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg5=$img5;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg6="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg6=$img6;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg7="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg7=$img7;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg8="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg8=$img8;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg9="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg9=$img9;}
	}
    $tbody=[
    $ProductType,
    $sku.'-'.$i,
    $brand,
    $row["proname"].",".$rows["cname"],
    $manufacturer,
	$recommended,
	$rows["saleprice"],
	$rows["kucun"],
	'Migrated Template',
	$btimg1,
	$btimg1,
	$btimg2,
	$btimg3,
	$btimg4,
	$btimg5,
	$btimg6,
	$btimg7,
	$btimg8,
	$btimg9,
	'child',
	$sku,
	'Variation',
	$row["btname"],
	'update',
	'',
	EAN13(randomkeys(12)),
	'EAN',
	'',
	$content,
	'',
	$des1,
	$des2,
	$des3,
	$des4,
	$des5,
	$des6,
	$key1,
	$key2,
	$key3,
	$key4,
	$key5,
	'',
	'',
	'',
	'',
	'',
	'',
	$cname2,
	'',
	'',
	'',
	$cname1,
	$cname1,
	$cname2,
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'New',
	'',
	'10',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	''
];
$writer->writeSheetRow('Sheet1', $tbody);
      }
    }
}

$writer->writeToStdOut();
}
?>